package fr.afcepf.atod21.brigade.service;

import java.util.Date;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import fr.afcepf.atod21.brigade.business.interfaces.EquipeBusiness;
import fr.afcepf.atod21.brigade.business.interfaces.InterventionBusiness;
import fr.afcepf.atod21.brigade.business.interfaces.VehiculeBusiness;
import fr.afcepf.atod21.brigade.dto.DtoConverter;
import fr.afcepf.atod21.brigade.dto.InterventionDto;
import fr.afcepf.atod21.brigade.entity.Equipe;
import fr.afcepf.atod21.brigade.entity.Intervention;
import fr.afcepf.atod21.brigade.entity.Vehicule;
import fr.afcepf.atod21.brigade.service.interfaces.InterventionService;

@Path("/intervention")
public class InterventionServiceImpl implements InterventionService{

	private InterventionBusiness businessIntervention;
	private VehiculeBusiness businessVehicule;
	private EquipeBusiness businessEquipe;

	public void setBusinessIntervention(InterventionBusiness businessIntervention) {
		this.businessIntervention = businessIntervention;
	}

	public void setBusinessVehicule(VehiculeBusiness businessVehicule) {
		this.businessVehicule = businessVehicule;
	}

	public void setBusinessEquipe(EquipeBusiness businessEquipe) {
		this.businessEquipe = businessEquipe;
	}

	@Override
	@Path("/countInterventions/{reve}")
	@GET
	@Produces(MediaType.TEXT_PLAIN)
	public int countInterventions(@PathParam("reve") int idReve) {
		List<Intervention> listeInterventions = businessIntervention.findAllByReve(idReve);
		return listeInterventions.size();
	}

	@Override
	@Path("/getInterventions")
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public List<InterventionDto> getInterventions() {
		List<InterventionDto> listeInterventionsDto = DtoConverter.InterventionsToInterventionsDto(businessIntervention.findAll());
		return listeInterventionsDto;
	}

	public Intervention createIntervention(int idReve, String adresse, String prenom, String nom){
		Intervention intervention = new Intervention();
		
		System.out.println(Math.random());
		Equipe equipe = businessEquipe.getEquipe(1);
		Vehicule vehicule = businessVehicule.getVehicule(1);
		intervention.setCommentaire("Plan déroulé sans accroc");
		intervention.setNumero(0);
		intervention.setAdresse(adresse);
		intervention.setTraite(0);
		intervention.setPrenom(prenom);
		intervention.setNom(nom);
		intervention.setDateDebut(new Date());
		intervention.setDateFin(new Date());
		intervention.setIdReve(idReve);
		intervention.setVehicule(vehicule);
		intervention.setEquipe(equipe);
		return intervention;
	}
}
